package dataStructArrayList;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Game {

    private static final String[] suits = {"♥","♣","♦","♠"};

    //  生成扑克牌
    public List<Poker> buyPoker(){
        List<Poker> pokers = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13 ; j++) {
//                String suit = suits[i];
//                int rank = j;
//                Poker poker = new Poker(suit,rank);
                Poker poker = new Poker(suits[i],j);
                pokers.add(poker);
            }
        }
        return pokers;
    }

    //  洗牌
    public void swapPoker(List<Poker> pokers){
        for (int i = pokers.size()-1; i > 0 ; i--) {
            // 找到随机 下标j
            Random random = new Random();
            int j = random.nextInt(i);
            //  创建一个临时变量接收 i下标 的值
            Poker tmp = pokers.get(i);
            //  将j位置的值给到 i位置
            pokers.set(i,pokers.get(j));
            //  将i位置的值给到 j位置
            pokers.set(j,tmp);
        }
    }

    //  揭牌,发牌
    public List<List<Poker>> takePoker(List<Poker> pokers){
        List<List<Poker>> hand = new ArrayList<>();
        List<Poker> hand1 = new ArrayList<>();
        List<Poker> hand2 = new ArrayList<>();
        List<Poker> hand3 = new ArrayList<>();
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);
        //  三个人，每人轮流抓五张牌
        //  最外层控制轮数
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Poker removePoke = pokers.get(0);
                pokers.remove(0);
                hand.get(j).add(removePoke);
            }
        }
        return hand;
    }


}
